package com.sz.web.common.service.serviceImp;

import com.sz.web.common.mapper.MyMapper;
import com.sz.web.common.pojo.ReturnPojo;
import com.sz.web.common.service.BaseService;
import com.sz.web.util.ReturnUtil;
import org.springframework.beans.factory.annotation.Autowired;

public class BaseServiceImp<T> implements BaseService<T> {
    @Autowired
    private MyMapper<T> myMapper;

    /**
     * 新增
     * @param o
     * @return
     */
    @Override
    public ReturnPojo insert(T o) {
        int res = myMapper.insert(o);
        return res > 0 ? ReturnUtil.success(o) : ReturnUtil.fail();
    }

    /**
     * 删除
     * @param o
     * @return
     */
    @Override
    public ReturnPojo delete(T o) {
        int res = myMapper.delete(o);
        return res > 0 ? ReturnUtil.success(o) : ReturnUtil.fail();
    }

    /**
     * 查询
     * @param o
     * @return
     */
    @Override
    public ReturnPojo select(T o) {
        Object res = myMapper.select(o);
        return ReturnUtil.success(res);
    }

    /**
     * 更新
     * @param o
     * @return
     */
    @Override
    public ReturnPojo update(T o) {
        int res = myMapper.updateByPrimaryKey(o);
        return res > 0 ? ReturnUtil.success(o) : ReturnUtil.fail();
    }
}
